from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-24 14:02:25.047060
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 24, Apr, 2022
Time: 14:02:30
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.0641
Nobs: 636.000 HQIC: -49.4497
Log likelihood: 7770.85 FPE: 2.61791e-22
AIC: -49.6945 Det(Omega_mle): 2.27497e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.326768 0.062374 5.239 0.000
L1.Burgenland 0.105330 0.039531 2.664 0.008
L1.Kärnten -0.110474 0.020718 -5.332 0.000
L1.Niederösterreich 0.195115 0.082652 2.361 0.018
L1.Oberösterreich 0.121151 0.081500 1.487 0.137
L1.Salzburg 0.258655 0.041967 6.163 0.000
L1.Steiermark 0.044329 0.055175 0.803 0.422
L1.Tirol 0.104266 0.044667 2.334 0.020
L1.Vorarlberg -0.064020 0.039433 -1.624 0.104
L1.Wien 0.024936 0.072231 0.345 0.730
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051925 0.133425 0.389 0.697
L1.Burgenland -0.034542 0.084561 -0.408 0.683
L1.Kärnten 0.041130 0.044318 0.928 0.353
L1.Niederösterreich -0.196289 0.176802 -1.110 0.267
L1.Oberösterreich 0.452117 0.174338 2.593 0.010
L1.Salzburg 0.285316 0.089771 3.178 0.001
L1.Steiermark 0.107325 0.118026 0.909 0.363
L1.Tirol 0.309750 0.095549 3.242 0.001
L1.Vorarlberg 0.024240 0.084352 0.287 0.774
L1.Wien -0.032310 0.154510 -0.209 0.834
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190257 0.031919 5.961 0.000
L1.Burgenland 0.089939 0.020229 4.446 0.000
L1.Kärnten -0.007697 0.010602 -0.726 0.468
L1.Niederösterreich 0.246505 0.042296 5.828 0.000
L1.Oberösterreich 0.159519 0.041707 3.825 0.000
L1.Salzburg 0.040941 0.021476 1.906 0.057
L1.Steiermark 0.025863 0.028235 0.916 0.360
L1.Tirol 0.085055 0.022858 3.721 0.000
L1.Vorarlberg 0.054342 0.020179 2.693 0.007
L1.Wien 0.116851 0.036963 3.161 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110529 0.032003 3.454 0.001
L1.Burgenland 0.043861 0.020282 2.162 0.031
L1.Kärnten -0.013744 0.010630 -1.293 0.196
L1.Niederösterreich 0.176563 0.042407 4.164 0.000
L1.Oberösterreich 0.332121 0.041816 7.942 0.000
L1.Salzburg 0.101794 0.021532 4.728 0.000
L1.Steiermark 0.111586 0.028309 3.942 0.000
L1.Tirol 0.093749 0.022918 4.091 0.000
L1.Vorarlberg 0.060195 0.020232 2.975 0.003
L1.Wien -0.017402 0.037060 -0.470 0.639
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112852 0.059749 1.889 0.059
L1.Burgenland -0.045030 0.037867 -1.189 0.234
L1.Kärnten -0.045782 0.019846 -2.307 0.021
L1.Niederösterreich 0.140334 0.079174 1.772 0.076
L1.Oberösterreich 0.162309 0.078070 2.079 0.038
L1.Salzburg 0.284197 0.040200 7.069 0.000
L1.Steiermark 0.057125 0.052853 1.081 0.280
L1.Tirol 0.161548 0.042788 3.776 0.000
L1.Vorarlberg 0.097834 0.037774 2.590 0.010
L1.Wien 0.076915 0.069191 1.112 0.266
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058131 0.047001 1.237 0.216
L1.Burgenland 0.028670 0.029788 0.962 0.336
L1.Kärnten 0.052237 0.015612 3.346 0.001
L1.Niederösterreich 0.201786 0.062282 3.240 0.001
L1.Oberösterreich 0.328680 0.061414 5.352 0.000
L1.Salzburg 0.038329 0.031624 1.212 0.225
L1.Steiermark 0.007902 0.041577 0.190 0.849
L1.Tirol 0.125532 0.033659 3.730 0.000
L1.Vorarlberg 0.065213 0.029714 2.195 0.028
L1.Wien 0.094379 0.054429 1.734 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170079 0.056315 3.020 0.003
L1.Burgenland 0.006098 0.035691 0.171 0.864
L1.Kärnten -0.065525 0.018705 -3.503 0.000
L1.Niederösterreich -0.099460 0.074623 -1.333 0.183
L1.Oberösterreich 0.206822 0.073583 2.811 0.005
L1.Salzburg 0.055658 0.037890 1.469 0.142
L1.Steiermark 0.240627 0.049815 4.830 0.000
L1.Tirol 0.501421 0.040328 12.434 0.000
L1.Vorarlberg 0.063433 0.035602 1.782 0.075
L1.Wien -0.076707 0.065214 -1.176 0.239
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.146436 0.062471 2.344 0.019
L1.Burgenland 0.001760 0.039592 0.044 0.965
L1.Kärnten 0.061342 0.020750 2.956 0.003
L1.Niederösterreich 0.174024 0.082780 2.102 0.036
L1.Oberösterreich -0.053842 0.081626 -0.660 0.510
L1.Salzburg 0.208326 0.042032 4.956 0.000
L1.Steiermark 0.137768 0.055261 2.493 0.013
L1.Tirol 0.061437 0.044737 1.373 0.170
L1.Vorarlberg 0.146553 0.039494 3.711 0.000
L1.Wien 0.118328 0.072343 1.636 0.102
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377476 0.036848 10.244 0.000
L1.Burgenland -0.002152 0.023353 -0.092 0.927
L1.Kärnten -0.021281 0.012239 -1.739 0.082
L1.Niederösterreich 0.208767 0.048828 4.276 0.000
L1.Oberösterreich 0.228921 0.048147 4.755 0.000
L1.Salzburg 0.038741 0.024792 1.563 0.118
L1.Steiermark -0.012537 0.032595 -0.385 0.701
L1.Tirol 0.091650 0.026388 3.473 0.001
L1.Vorarlberg 0.052826 0.023296 2.268 0.023
L1.Wien 0.039836 0.042671 0.934 0.351
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035793 0.111243 0.173037 0.139890 0.101300 0.082374 0.036865 0.209295
Kärnten 0.035793 1.000000 -0.022609 0.133002 0.051555 0.088496 0.443152 -0.063588 0.090915
Niederösterreich 0.111243 -0.022609 1.000000 0.320765 0.127472 0.281767 0.072414 0.158923 0.295063
Oberösterreich 0.173037 0.133002 0.320765 1.000000 0.218529 0.305489 0.169196 0.143485 0.244948
Salzburg 0.139890 0.051555 0.127472 0.218529 1.000000 0.128809 0.095626 0.108521 0.127280
Steiermark 0.101300 0.088496 0.281767 0.305489 0.128809 1.000000 0.138993 0.115571 0.044407
Tirol 0.082374 0.443152 0.072414 0.169196 0.095626 0.138993 1.000000 0.067381 0.150438
Vorarlberg 0.036865 -0.063588 0.158923 0.143485 0.108521 0.115571 0.067381 1.000000 0.000591
Wien 0.209295 0.090915 0.295063 0.244948 0.127280 0.044407 0.150438 0.000591 1.000000